/** @format */
let loginPromise = null;
export default function login() {
 if (loginPromise) return loginPromise;
 const xlj_openid = uni.getStorageSync('xlj_openid');
 if (!xlj_openid) {
  loginPromise = uni
   .login({
    provider: 'weixin',
   })
   .then((res) => {
    console.log('我要打印的值:', res);
    const authAction = uniCloud.importObject('auth-action'); //第一步导入云对象
    return authAction.login(res).then(
     (c) => {
      const { data } = c;
      const { openid } = data;
      uni.setStorageSync('xlj_openid', openid);
     },
     (v) => {
      console.log('error', v);
     }
    );
   });
  return loginPromise.finally(() => (loginPromise = null));
 }
 return xlj_openid;
}
